import java.util.ArrayList;

public class StreamDemo1 {
    public static void main(String[] args) {
        ArrayList<String> alt = new ArrayList<>();
        alt.add("Jack");
        alt.add("Mark");
        alt.add("Marry");
        alt.add("May");
        alt.add("Tom");
        alt.add("Tony");
        alt.add("Linda");
        System.out.println(alt);
        ArrayList<String> Ma_alt = new ArrayList<>();
        for(String str : alt){
            if(str.startsWith("Ma"))
                Ma_alt.add(str);
        }
        System.out.println(Ma_alt);
        ArrayList<String> three_alt = new ArrayList<>();
        for(String str : Ma_alt)
            if(str.length() == 3)
                three_alt.add(str);
        System.out.println(three_alt);
        //这种过滤方式太繁琐了，下面使用stream改进
        alt.stream().filter(s -> s.startsWith("Ma")).filter(s-> s.length() == 3).forEach(System.out::println);
    }
}
